﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using WPControla.Client.Views;
using Microsoft.Phone.Controls;

namespace WPControla.Client.Services
{
    /// <summary>
    /// Phone navigation service wrapper to access from viewmodel.
    /// </summary>
    public class NavigationService : INavigationService
    {
        Entities.PodcastItem _selectedChapter;

        public void NavigateToArticle(Entities.RssItem selectedArticle)
        {
            throw new NotImplementedException();
        }

        public void NavigateToChapter(Entities.PodcastItem selectedChapter)
        {
            _selectedChapter = selectedChapter;
            (App.Current.RootVisual as PhoneApplicationFrame).Navigated += new NavigatedEventHandler(NavigationServiceChapter_Navigated);
            (App.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/Views/ViewChapter.xaml", UriKind.RelativeOrAbsolute));
        }

        void NavigationServiceChapter_Navigated(object sender, NavigationEventArgs e)
        {
            (App.Current.RootVisual as PhoneApplicationFrame).Navigated -= NavigationServiceChapter_Navigated;
            if (e.Content.GetType() == typeof(ViewChapter))
                (e.Content as ViewChapter).Item = _selectedChapter;
        }

        public void NavigateToTweet(Entities.Rss selectedTweet)
        {
            throw new NotImplementedException();
        }
    }
}
